//
// Created by Abstergo on 2024/6/14.
//

#ifndef TBS_CPP_RANGEINL_CUH
#define TBS_CPP_RANGEINL_CUH

const size_t RangeIterator::index() const {
  return (size_t)_b;
}

const void *RangeIterator::source() const {
  return reinterpret_cast<const void *>(_b);
}

int &RangeIterator::value() {
  return _b;
}

bool RangeIterator::has_next() const {
  return _b < _e;
}

Iterator<int> &RangeIterator::next() {
  _b = _b + _step > _e ? _e : _b + _step;
  return *this;
}

RangeIterator::RangeIterator(int b, int e, int step)
	: _b(b), _e(e), _step(step) {
  ASSERT(b > e || step <= 0,
		 LOG_FORMAT("b:{} ,e:{},s:{}.b must smaller than e and s must gather then 0", b, e, step))
}

RangeIterator IntRange::end() NO_EXCEPT {
  return RangeIterator(_e, _e, _s);
}

RangeIterator IntRange::begin() NO_EXCEPT {
  return RangeIterator(_b, _e, _s);
}

IntRange::IntRange(int b, int e, int s)
	: _b(b), _e(e), _s(s) {
  ASSERT(b > e || s <= 0,
		 LOG_FORMAT("b:{} ,e:{},s:{}.b must smaller than e and s must gather then 0", b, e, s))
}
#endif //TBS_CPP_RANGEINL_CUH
